/*
 * Description: performance common utilities.
 */
#ifndef PERF_UTILS_H
#define PERF_UTILS_H

#include <string>
#include <vector>
#include "Windows.h"
#include "error.h"
#include "singleton.h"

namespace PERF {

constexpr const size_t DEFAULT_NAME_SIZE = 64;
const int SYSTEM_IDLE_PROCESS = 0;
const int SYSTEM_SYSTEM_PROCESS = 4;
class PerfUtils {
public:
    std::vector<std::string> Split(const std::string &str, const std::string &delim);
    std::vector<std::wstring> SplitUnicode(const std::wstring &str, const std::wstring &delim);
    void ToLower(std::vector<std::string> &strs);
    std::string GetCurrentUserSid();
    DWORD GetProcessIdByName(LPCTSTR pszExeFile);
    bool QueryProcessNameByPid(IN DWORD pid, OUT std::wstring& processFullName);
    bool QueryProcessNameByPid(IN DWORD pid, OUT std::string& processFullName);
    bool IsProcessExists(IN DWORD processId);
    bool IsProcessExists(IN const std::wstring& processName);
    bool IsProcessExists(IN const std::string &processName);
    bool GetFilepathFromCmdLine(const std::string &cmdLine, std::string &filepath);
    bool GetUserToken(HANDLE* phToken);
private:
    bool LookupCurrentUserSid(HANDLE& hToken, SID*& sid);
    std::string userSid;
};
#define PERF_UTILS SingletonNew<PERF::PerfUtils>::GetInstance()
}  // namespace PERF

#endif